package com.liusaidh.config;

import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.filter.HiddenHttpMethodFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.Filter;


//web工程的初始化类，代表web.xml
public class WebInit extends AbstractAnnotationConfigDispatcherServletInitializer {

    @Override //配置过滤器
    protected Filter[] getServletFilters() {
        //配置编码过滤器，解决Post请求乱码的问题
        CharacterEncodingFilter cef = new CharacterEncodingFilter();
        cef.setEncoding("UTF-8");
        cef.setForceRequestEncoding(true);
        HiddenHttpMethodFilter hmf = new HiddenHttpMethodFilter();
        return new Filter[]{cef,hmf};
    }

    @Override //指定Spring的配置类
    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{SpringConfig.class};
    }

    @Override //指定SpringMvc的配置类
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{SpringMvcConfig.class};
    }

    @Override //指定DispatchServlet的映射规则  即<url-pattern>/</url-pattern>
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }
}
